import { InitializeSessionTable } from "./model/session.ts";
import { InitializeMessageTables } from "./model/message.ts";
import betterSqlite3Type from "better-sqlite3";
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const Database = require("better-sqlite3");
// 初始化数据库
export function InitDb(dabasePath: string): betterSqlite3Type.Database {
  try {
    const db = new Database(dabasePath);
    InitializeSessionTable(db);
    InitializeMessageTables(db);
    db.pragma("journal_mode = WAL");
    return db;
  } catch (error) {
    console.error("数据库初始化失败:", error);
    throw error;
  }
}
